//
//  ZZCDueController.m
//  ZZC-Finance
//
//  Created by mac on 2017/6/10.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZZCDueController.h"
#import "ZZCDueView.h"
#import "ZZCDue.h"

static NSString *dueCell = @"dueCell";
@interface ZZCDueController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) UITableView *dueTableView;
@property (strong, nonatomic) NSMutableArray *dueArray;
@property (strong, nonatomic) NSArray *dueData;
@property (copy  , nonatomic) NSString *count;//总金额
@property (strong, nonatomic) ZZCDue *dueModel;
@end

@implementation ZZCDueController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self requestDueData];
    [self.view addSubview:self.dueTableView];
}

- (void)requestDueData {
    NSString *token = ZZCNSUserDefaults(@"token");
    NSDictionary *dict = @{@"token":token};
    NSString *sign = [ZZCRequest getSignWithDict:dict];
    sign = [NSString md5:[sign lowercaseString]];
    NSDictionary *param = @{@"timestamp":[NSString timeStr],@"sign":sign,@"token":token};
    [[ZZCRequest sharedNetworkTools] POST:ZZCURL_API_USERASSETS parameters:param finished:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (error) {
            ZZCLog(@"失败-%@",error);
        }else {
            ZZCLog(@"-*************%@",responseObject);
            NSLog(@"%@/%@",ZZCURL_API_USERASSETS,token);
            self.count = responseObject[@"data"][@"count"];
            self.dueModel = [ZZCDue mj_objectWithKeyValues:responseObject[@"data"][@"list"]];
            [self.dueTableView reloadData];
        }
    }];
}


#pragma mark  - 数据源
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //填你后台返个数
    return 1;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dueCell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:dueCell];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    ZZCDueView *headView = [ZZCDueView dueView];
    headView.countLabel.text = [NSString stringWithFormat:@"%@",self.count];
    headView.iouLabel.text = [NSString stringWithFormat:@"%@",self.dueModel.iou];
    headView.iousLabel.text = [NSString stringWithFormat:@"%@",self.dueModel.ious];
    headView.loanLabel.text = [NSString stringWithFormat:@"%@",self.dueModel.loan];
    headView.engineeringLabel.text = [NSString stringWithFormat:@"%@",self.dueModel.engineering];
    headView.materialLabel.text = [NSString stringWithFormat:@"%@",self.dueModel.material];
    headView.folkloanLabel.text = [NSString stringWithFormat:@"%@",self.dueModel.folkloan];
    headView.contractLabel.text = [NSString stringWithFormat:@"%@",self.dueModel.contract];
    headView.companyLabel.text = [NSString stringWithFormat:@"%@",self.dueModel.company];
    headView.projectLabel.text = [NSString stringWithFormat:@"%@",self.dueModel.project];
    headView.p2pLabel.text = [NSString stringWithFormat:@"%@",self.dueModel.p2p];
    headView.financialLabel.text = [NSString stringWithFormat:@"%@",self.dueModel.financial];
    headView.frame = CGRectMake(0, 0, ZZCScreenW, ZZCScreenH);
    return headView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 584;
}
- (UITableView *)dueTableView {
    if (_dueTableView == nil) {
        _dueTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ZZCScreenW, ZZCScreenH-113) style:UITableViewStyleGrouped];
        _dueTableView.backgroundColor = [UIColor colorWithHex:0xeaeaea];
        _dueTableView.delegate = self;
        _dueTableView.dataSource = self;
        _dueTableView.separatorStyle = NO;
        _dueTableView.showsVerticalScrollIndicator = NO;
        _dueTableView.rowHeight = 200;
    }
    return _dueTableView;
}


- (NSMutableArray *)dueArray {
    if (_dueArray == nil) {
        _dueArray = [NSMutableArray array];
    }
    return _dueArray;
}

- (NSArray *)dueData {
    if (_dueData == nil) {
        _dueData = [NSArray array];
    }
    return _dueData;
}
@end

